#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 1e6 + 10;
const int M = 998244353, mod = M;

ll dp[N], dp1[N], dp2[N];
int n;
ll res = 0;

ll inv(ll a, ll p = M)
{
    return (a == 1) ? 1 : inv(p % a, p) * (p - p / a) % p;
}

// a/b % p
ll frac_inv(ll a, ll b, ll p = M)
{
    return (a * inv(b, p)) % p;
}

ll g(ll n)
{
    if (n < 0)
        return 0;
    ll t = dp[n];
    res = (t * (t + 1)) % M;
    res = (res * (t + 5)) % M;
    res = (res * inv(3)) % M;
    return (res + M) % M;
}

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    while (cin >> n)
    {
        dp[0] = dp1[0] = dp2[0] = 1;

        for (int i = 1; i <= n; i++)
        {
            dp[i] = ((dp[i - 1] + 1) * (dp[i - 1] + 2) / 2) % M;
            dp1[i] = dp[i] - dp[i - 1];
            dp2[i] = dp1[i] - dp1[i - 1];
        }

        res = (g(n - 1) - g(n - 2)) % M;
        for (int i = 0; i < n; i++)
            res = (res + dp2[i] * dp1[n - 1 - i]) % M;

        cout << (res + M) % M << endl;
    }
    return 0;
}